package com.xfc.config;


import com.xfc.config.interceptor.Interceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpMethod;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author lcj
 * @date 
 */
@Configuration
public class ContainerWebAppConfigurer implements WebMvcConfigurer {
	
	/**
	 * 这里需要先将限流拦截器入住，不然无法获取到拦截器中的redistemplate
	 * @return
	 */
	@Bean
	public Interceptor getAccessLimitIntercept() {
		return new Interceptor();
	}
 
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getAccessLimitIntercept()).addPathPatterns("/**")
				//添加不拦截路径
				.excludePathPatterns(
				//登录/注册
				"/wx/login","/wx/register","/wx/sendCode","/api/audition/**","/wx/sendReservationCode",
				//swagger
				"/**/swagger-ui/**", "/**/swagger-resources/**", "/**/v3/**", "/swagger-ui.html"
		);
	}


	@Override
	public void addResourceHandlers(ResourceHandlerRegistry registry) {
		registry.addResourceHandler("swagger-ui.html")
				.addResourceLocations("classpath:/META-INF/resources/");
		registry.addResourceHandler("/webjars/**")
				.addResourceLocations("classpath:/META-INF/resources/webjars/");
	}

}